package com.itheima.thread;

public class Demo02 {

    public static void main(String[] args) {
        MyRunnable my = new MyRunnable();
        Thread t1 = new Thread(my);
        t1.setName("大象");
        t1.start();
        Thread t2 = new Thread(my);
        t2.setName("河马");
        t2.start();
      /* new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("匿名内部类中执行到了"+i);
                }
            }
        }).start();*/
       /* new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.println("lambda中执行到了" + i);
            }
        }).start();*/
        String name = Thread.currentThread().getName();
        for (int i = 0; i < 100; i++) {

            System.out.println(name+"中执行到了" + i);
        }
    }
}
class MyRunnable  implements Runnable {

    @Override
    public void run()  {//内部如果有异常 只能自己处理
        Thread thread = Thread.currentThread();
        for (int i = 0; i < 100; i++) {
        //在这里获取线程对象

            System.out.println(thread.getName()+"中执行到了" + i);
        }
    }
}

